package server

import (
	"exam2.12/model"
	"github.com/gin-gonic/gin"
)

type ServerOrder struct {
	id        int
	order_no  string
	goods_id  string
	price     string
	goods_sum string
}

// 添加订单
func (o *ServerOrder) Add(g *gin.Context) {
	o.order_no = g.PostForm("order_no")
	o.goods_id = g.PostForm("goods_id")
	o.price = g.PostForm("price")
	o.goods_sum = g.PostForm("goods_sum")
	order := model.Order{}
	goods := model.Goods{}
	//判断是否有库存
	err := goods.GoodsFind(o.goods_sum)
	if err != nil {
		g.JSON(200, err)
	}
	err = order.Add(o)
	if err != nil {
		g.JSON(200, err)
		return
	}

}

// 订单回滚
func (o *ServerOrder) OrderRollBack(g *gin.Context) {
	id := g.PostForm("id")
	order := model.Order{}
	err := order.OrderRollBack(id)
	if err != nil {
		g.JSON(200, err)
	}
}
